# Maintainer: Diego Sogari <diego.sogari@gmail.com>

_realname=cjose
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.6.2.3
pkgrel=1
pkgdesc="C library implementing the Javascript Object Signing and Encryption (JOSE) (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/OpenIDC/cjose"
license=('spdx:MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-check")
depends=("${MINGW_PACKAGE_PREFIX}-jansson"
         "${MINGW_PACKAGE_PREFIX}-openssl")
source=("https://github.com/OpenIDC/cjose/releases/download/v${pkgver}/cjose-${pkgver}.tar.gz"
        "001-cjose-0.6.1-fix-mingw-build.patch")
sha256sums=('2c5f930ddcb09be7db04ab6ffb679b20aa5f24f4fc26f47cc63bc01c19c9fe11'
            'f8458531926bb61377b8d93628235a88321a9a6184ec899f994a2aa1f66d4531')
noextract=("${_realname}-${pkgver}.tar.gz")

prepare() {
  cd "${srcdir}"
  rm -rf "${_realname}-${pkgver}"
  tar -xzvf "${_realname}-${pkgver}.tar.gz" --exclude lib

  cd "${_realname}-${pkgver}"
  patch -Np1 -i "${srcdir}/001-cjose-0.6.1-fix-mingw-build.patch"
  autoreconf --force --install
  sed -e "s|-Werror||g" -i src/Makefile*
}

build() {
  cp -r ${_realname}-${pkgver} build-${MSYSTEM} && cd build-${MSYSTEM}

  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --with-openssl=${MINGW_PREFIX} \
    --with-jansson=${MINGW_PREFIX}

  make
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"
  make test
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  make DESTDIR="${pkgdir}" install
}
